<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateCountPendingTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up(): void
    {
        $table = $this->table('count_pending', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '数据统计']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('type', 'string', ['default' => '', 'limit' => 128, 'comment' => '数据统计类型'])
            ->addColumn('project_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '所属项目id'])
            ->addColumn('episode_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '所属集数id'])
            ->addColumn('step_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '所属工序id'])
            ->addColumn('number', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '统计数量'])
            ->addColumn('updated', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新时间'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间']);

        $table->addIndex(['type', 'project_id', 'episode_id', 'step_id'], ['unique' => true, 'name' => 'idx_data_unique']);

        //执行创建
        $table->create();
    }

    public function down()
    {
        $this->table('count_pending')->drop()->save();
    }
}
